<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>险种配置关系表 管理</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<form id="insTypCfgR_form">
    <div class="fieldset1 tabel_col tabel_col_1 clearFix">

        <div class="fieldBox col_100">
            <div class="label">险种</div>
            <div class="field">
                <input name="insTypId" id="insTypId" data-value="${insTypCfgRVO.insTypId}"
                       placeholder="请选择" ltype="combobox" validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">事业部</div>
            <div class="field">
                <input name="buOrgCd" id="buOrgCd" data-value="${insTypCfgRVO.buOrgCd}"
                       placeholder="请选择" ltype="combobox" validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">项目类型</div>
            <div class="field">
                <input name="prjTypCd" id="prjTypCd" data-value="${insTypCfgRVO.prjTypCd}"
                       placeholder="请选择" ltype="combobox" validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">是否必要</div>
            <div class="field">
                <input type="checkbox" id="isFstReq" <c:if test="${insTypCfgRVO.isFstReq==1}">checked</c:if> name="isFstReq">首年保单
                <input type="checkbox" id="isRenewReq" <c:if test="${insTypCfgRVO.isRenewReq==1}">checked</c:if> name="isRenewReq">续保保单
            </div>
        </div>
    </div>
    <div class="btnsBox">
        <span id="saveInsTypCfgR_Btn" class="sq-button sq-button-round">保存</span>
    </div>
</form>
<script>
    $(function () {
        var insTypCfgRId = "${insTypCfgRVO.id}";//主键ID

        $("#insTypId").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        $("#buOrgCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
            onChangeValue: function (value) {
                buOrgCd=liger.get("buOrgCd").getValue();
                $.ajax({
                    type: 'get',
                    dataType: 'json',
                    url: '<%=path%>/insurance/insTypCfgR/getPrjTypList.do?buOrgCd='+buOrgCd,
                    success: function (msg) {
                        if (msg.success == 1) {
                            liger.get("prjTypCd").setData(JSON.parse(msg.data));
                        }
                    }
                });
            }
        });
        $("#prjTypCd").ligerComboBox({
            isShowCheckBox: true,
            isMultiSelect: true,
            addRowButton: "add",
            valueField: 'key',
            textField: 'value'
        });

        $("#insTypCfgR_form").ligerForm({
            validate: true
        });
        liger.get("insTypId").setData(${insTypCdList});
        liger.get("buOrgCd").setData(${buOrgCdList});
        liger.get("prjTypCd").setData(${prdTypCdList});

        if(insTypCfgRId){//修改操作
            liger.get("insTypId").setDisabled();
            liger.get("buOrgCd").setDisabled();
            liger.get("prjTypCd").setDisabled();
        }

        /*保存*/
        $("#saveInsTypCfgR_Btn").click(function (event) {
            var form = liger.get("insTypCfgR_form");
            if (!form.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            var data = form.getData();
            $.ligerDialog.hide();
            var _url;
            if (insTypCfgRId == '') {//新增
                _url = '<%=path%>/insurance/insTypCfgR/add.do';
            } else {//修改
                _url = '<%=path%>/insurance/insTypCfgR/modify.do?id=' + insTypCfgRId;
            }
            if(data.isFstReq){
                data.isFstReq=1;
            }else{
                data.isFstReq=0;
            }
            if(data.isRenewReq){
                data.isRenewReq=1;
            }else{
                data.isRenewReq=0;
            }
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: data,
                url: _url,
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        parent.$("#clearBtn").click();
                        parent.$("#searchBtn").click();
                        frameElement.dialog.close();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    });
</script>
</body>
</html>
